eval(loadFile("main/src/viz.js"));

var graphics;
var screen;

testCases(test,
    function setUp() {
        graphics = {};
        screen = viz.screen();
    },

    function shouldGetWidthOfFrameAssetAcrossMultipleSlides() {
        var firstSlide = {
            asset1 : {
                id : "asset1",
                width : function (graphics) {
                    return 25;
                }
            }
        };
        var secondSlide = {
            asset1 : {
                id : "asset1",
                width : function (graphics) {
                    return 35;
                }
            }
        };
        screen.placeFrameAsset(0, firstSlide.asset1);
        screen.placeFrameAsset(1, secondSlide.asset1);

        assert.that(screen.widthOf("asset1", graphics), eq(35));
    },

    function shouldGetSumOfFrameAssetWidthAsScreenWidth() {
        var firstSlide = {
            asset1 : {
                id : "asset1",
                width : function (graphics) {
                    return 25;
                }
            },
            asset2 : {
                id : "asset2",
                width : function (graphics) {
                    return 35;
                }
            }
        };
        screen.placeFrameAsset(0, firstSlide.asset1);
        screen.placeFrameAsset(0, firstSlide.asset2);

        assert.that(screen.width(graphics), eq(60));    
    },

    function shouldGetMaximumOfFrameAssetHeightAsScreenHeight() {
        var firstSlide = {
            asset1 : {
                id : "asset1",
                height : function (graphics) {
                    return 25;
                }
            },
            asset2 : {
                id : "asset2",
                height : function (graphics) {
                    return 15;
                }
            }
        };
        var secondSlide = {
            asset1 : {
                id : "asset1",
                height : function (graphics) {
                    return 35;
                }
            }
        };
        screen.placeFrameAsset(0, firstSlide.asset1);
        screen.placeFrameAsset(0, firstSlide.asset2);
        screen.placeFrameAsset(1, secondSlide.asset1);

        assert.that(screen.height(graphics), eq(35));
    },

    function shouldDrawFrameAssetsFromPreviousSlidesWhenCurrentSlideIsDrawn() {
        var firstSlide = {
            asset1 : {id : "asset1"},
            asset2 : {id : "asset2"}
        };
        var secondSlide = {
            asset2 : {id : "asset2"}
        };
        screen.addFrameAsset(0, firstSlide.asset1);
        screen.addFrameAsset(0, firstSlide.asset2);
        screen.addFrameAsset(1, secondSlide.asset2);

        var notDefined;
        firstSlide.asset1.draw = assert.functionThatMustBeCalled("draw", function (graphics, coordinate) {
            assert.that(coordinate, eq(notDefined));
        });
        secondSlide.asset2.draw = assert.functionThatMustBeCalled("draw", function (graphics, coordinate) {
            assert.that(coordinate, eq(notDefined));
        });
        screen.drawFrameAssets(1, graphics);
    },

    function shouldDrawFrameAssetFromPreviousSlidesWithLocalisedCoordinateWhenCurrentSlideIsDrawn() {
        var firstSlide = {
            asset1 : {
                id : "asset1",
                width : function (graphics) {
                    return 25;
                }
            },
            asset2 : {id : "asset2"}
        };
        screen.placeFrameAsset(0, firstSlide.asset1);
        screen.placeFrameAsset(0, firstSlide.asset2).placedAfter(firstSlide.asset1);

        firstSlide.asset1.draw = assert.functionThatMustBeCalled("draw", function (graphics, coordinate) {
            assert.that(coordinate.x(), eq(0));
            assert.that(coordinate.y(), eq(0));
        });
        firstSlide.asset2.draw = assert.functionThatMustBeCalled("draw", function (graphics, coordinate) {
            assert.that(coordinate.x(), eq(25));
            assert.that(coordinate.y(), eq(0));
        });
        screen.drawFrameAssets(0, graphics);
    }
);